package com.example.projectmanagement.model;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime;

@Entity
@Table(name = "sys_user")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(unique = true, nullable = false)
    private String username;

    @Column(nullable = false)
    private String password;

    @Column(nullable = false)
    private String name;

    private String phone;

    private String department;

    @Column(nullable = false)
    private Integer status = 1; // 1-启用，0-禁用

    @Column(nullable = false)
    private String role = "STUDENT"; // 默认角色

    @Column(name = "login_fail_count")
    private Integer loginFailCount = 0;

    @Column(name = "lock_time")
    private LocalDateTime lockTime;
    
    @Column(name = "avatar")
    private String avatar; // 头像图片文件路径
    
    // Study management specific fields
    @Column(name = "nickname")
    private String nickname; // 昵称
    
    @Column(name = "gender")
    private String gender; // 性别
    
    @Column(name = "birth_date")
    private LocalDateTime birthDate; // 出生日期
    
    @Column(name = "bio", length = 500)
    private String bio; // 个人简介
    
    @Column(name = "study_points")
    private Integer studyPoints = 0; // 学习积分
    
    @Column(name = "study_level")
    private Integer studyLevel = 1; // 学习等级
    
    @CreatedDate
    @Column(name = "create_time", updatable = false)
    private LocalDateTime createTime;

    @LastModifiedDate
    @Column(name = "update_time")
    private LocalDateTime updateTime;
}